package cn.szzsi.common.model.zshop;

import cn.szzsi.core.kit.CommonUtil;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.util.*;

/**
 * 实体类 - 会员
 */
public class Member extends BaseMember<Member> {

    private static final long serialVersionUID = 1312507976941245078L;

    public static final Member dao = new Member().use(CommonUtil.ZSHOP).dao();

    /**
     * 根据手机号查询该商户是都注册
     * @param phone
     * @return
     */
    public Member getByPhone(String phone) {
        return Member.dao.findFirst("select * from sys_member where phone=? and shopId=0", phone);
    }

    /**
     * 根据推荐码获取会员对象(平台)
     * @param agentCode
     * @return
     */
    public Member getByCode(String agentCode){
        return dao.findFirst("select * from sys_member where agentCode = ?", agentCode);
    }

    public static final Member saveBusiness(String phone,String username,String password,String userimgurl){
        Member member=new Member().use(CommonUtil.ZSHOP);
        member.set("id", CommonUtil.getUUID());
        member.set("username", username);
        member.set("password", DigestUtils.md5Hex(password));
        member.set("userimgurl", userimgurl);
        member.set("shopId", "0");
        member.set("createDate", new Date());
        member.set("roleId", "super");
        member.set("b_shoprank", "super");
        member.set("isAccountEnabled", 1);
        member.set("isAccountLocked", 0);
        member.set("loginFailureCount", 0);
        member.set("phone", phone);
        member.set("registerIp", "");
        member.setType(1);//商户
        member.save();
        return member;
    }

}
